package se.webbzon.boltzmann.menu;

import java.awt.image.ImageObserver;

public class PageLabel extends MLabel {
	
	// The maximal number of characters used for the path
	private static final int pathSize = 64;
	
	// The prefix and the separator used for the path
	private static final String prefix = "...", separator = " > ";

	/*============================================================
	Constructors
	============================================================*/
	
	public PageLabel(ImageObserver observer, LabelLayout layout, MPage page) {
		super(observer, layout, true, getPath(page,pathSize));
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Returns a string describing the path to the given game menu page. **/
	private static String getPath(MPage page, int remaining) {
		if (page.getParent() == null) {
			if (page.getName().length() <= remaining)
				return page.getName();
			else
				return prefix;
		} else {
			final int length = page.getName().length() + separator.length();
			if (length + prefix.length() <= remaining)
				return getPath(page.getParent(),remaining - length) + separator + page.getName();
			else
				return prefix;
		}
	}

}
